﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using OTS.Common;
using OTS.BLL;
using OTS.Model;

public partial class Admin_login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Test();
    }
    private void Test()
    {
        string sname = "admin";
        string spwd = "admin";
        string scode = "admin";

        if (sname == "")
        {
            OTS.Common.Jscript.AlertAndRedirect("用户名不能为空", "login.aspx");
            return;
        }
        if (spwd == "")
        {
            OTS.Common.Jscript.AlertAndRedirect("密码不能为空", "login.aspx");
            return;
        }

        string strCheckCode = "";// Request.Cookies.Get("CheckCode").Value;

        OTS.BLL.SysUserBLL uBLL = new OTS.BLL.SysUserBLL();
        OTS.Model.sys_user user = uBLL.Login(sname, spwd);
        if (user == null)
        {
            OTS.Common.Jscript.AlertAndRedirect("用户名或密码输入错误！", "login.aspx");
            return;
        }

        OTS.Model.SessionUser suser = new OTS.Model.SessionUser();
        suser.password = user.password;
        suser.realname = user.realName;
        suser.uid = user.uid;
        suser.rid = user.rid;
        suser.rosename = user.rosename;
        List<Int32> numlist = new List<int>();
        List<OTS.Model.sys_right> list = new OTS.BLL.SysRoseBLL().GetAllSysRightByRoseID(user.rid);
        for (int i = 0; i < list.Count; i++)
        {
            numlist.Add(list[i].rtid);
        }
        suser.myright = numlist;
        OTS.BaseLogin.SetSession(HttpContext.Current, suser);

        //日志
        OTS.BLL.SysLogBLL.AddLogInfo(suser, OTS.Model.enumLogDesNO.LOG_DES_LOGIN, "login.aspx", HttpContext.Current.Request.UserHostAddress);
        Response.Redirect("Index.aspx");

    }

    protected void LoginButton_Click(object sender, ImageClickEventArgs e)
    {
        string sname = username.Text;
        string spwd = password.Text;
        string scode = code.Text;
 
        if(sname == "")
        {
            OTS.Common.Jscript.AlertAndRedirect("用户名不能为空", "login.aspx");
            return;
        }
        if(spwd == "")
        {
            OTS.Common.Jscript.AlertAndRedirect("密码不能为空", "login.aspx");
            return;
        }

        string strCheckCode = Request.Cookies.Get("CheckCode").Value;
  
        OTS.BLL.SysUserBLL uBLL = new OTS.BLL.SysUserBLL();
        OTS.Model.sys_user user = uBLL.Login(sname, spwd);
        if (user == null)
        {
            OTS.Common.Jscript.AlertAndRedirect("用户名或密码输入错误！", "login.aspx");
            return;
        }

        OTS.Model.SessionUser suser = new OTS.Model.SessionUser();
        suser.password = user.password;
        suser.realname = user.realName;
        suser.uid = user.uid;
        suser.rid = user.rid;
        suser.rosename = user.rosename;
        List<Int32> numlist = new List<int>();
        List<OTS.Model.sys_right> list = new OTS.BLL.SysRoseBLL().GetAllSysRightByRoseID(user.rid);
        for (int i = 0; i < list.Count; i++)
        { 
            numlist.Add(list[i].rtid);
        }
        suser.myright = numlist;
        OTS.BaseLogin.SetSession(HttpContext.Current, suser);

        //日志
        OTS.BLL.SysLogBLL.AddLogInfo(suser, OTS.Model.enumLogDesNO.LOG_DES_LOGIN, "login.aspx",HttpContext.Current.Request.UserHostAddress);
        Response.Redirect("Index.aspx");

    }
}
